const express = require('express');
const bodyParser = require('body-parser');
const server = express();
server.use(bodyParser.urlencoded({extended:false}));
server.use(bodyParser.json());
server.use((req, res, next) => {
   res.header('Access-Control-Allow-Origin','*');
   res.header('Access-Control-Allow-Headers', '*');
   res.header('Access-Control-Allow-Methods','*');
   res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE');
   res.header('X-Powered-By','3.2.1')
   res.header('Content-Type', 'application/json;charset=utf-8');
   next();
});
server.get('/list', (req, res) => {
   const names = ['Orange', 'Apricot', 'Apple', 'Plum', 'Pear', 'Pome', 'Banana', 'Cherry', 'Grapes', 'Peach'];
   const list = names.map((name, id) => {
   return {
      id: ++id,
      name,
      price: Math.ceil(Math.random() * 100)
    };
  });

res.end(JSON.stringify({ code: 0, data: list, message: ''}));
});
server.get('/pic', (req, res) => {
    res.end(JSON.stringify({ code: 0, data:'http://c-ssl.duitang.com/uploads/blog/202103/03/20210303123007_f2661.thumb.1000_0.jpeg', message: ''}));
});
server.post('/login',(req,res)=>{
    // res.set("name",'real');
    res.send({
        data:200,
        result:{
            username:"real",
            password:"123456"
        }
    });
})
server.listen(5656, () => {
    console.log('listen at http://localhost:5656/');
});